<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class AdminIdentity extends CU {
    
    /**
     *  user is denied
     */
    const ERROR_STATE_INVALID=11;
    private $_id;
    
    public function authenticate() {

        $authModel = User::model()->findByAttributes(array('username' => $this->username));

        if (!$authModel || $authModel->count() == 0) {
            $this->errorCode = self::ERROR_USERNAME_INVALID;
        } else if ($authModel && $authModel->password !== md5($this->password)) {
            $this->errorCode = self::ERROR_PASSWORD_INVALID;
        } else if ($authModel && $authModel->status != 1) {
            $this->errorCode = self::ERROR_STATE_INVALID;
        } else {
            $this->errorCode = self::ERROR_NONE;
            $this->_id=$authModel->user_id;
        }

        return !$this->errorCode;
    }
    
    public function getId() {
        return $this->_id;
    }

}

?>
